<template>
  <div class="divBox relative">
    <el-card class="box-card">
      <div slot="header" class="clearfix">
		
        <div class="container mt-1">
          <el-form inline size="small">
			<div class="flex items-center search_form">
				<div>
					活动名称：
					<el-input
					v-model="searchForm.title"
					placeholder="请输入活动名称"
					style="width: 200px; margin-right: 10px;"
					size="small"
					></el-input>
				</div>
				<div>
					所属人：
					<el-select v-model="searchForm.owner_id" style="width: 200px; margin-right: 10px;" size="small" placeholder="请选择所属人">
					  <el-option
					    v-for="item in shopUser"
					    :key="item.id"
					    :label="item.name"
					    :value="item.id"
					  />
					</el-select>
				</div>
				 <div>
					<el-button type="primary" size="mini" @click="mySearch">搜索</el-button>
					<el-button size="mini" @click="reset">重置</el-button>
				 </div>
			</div>
			
           
			
           
          </el-form>
        </div>
      </div>
      <el-table
        :data="list"
        style="width: 100%"
        size="mini"
        height="500px"
        :highlight-current-row="true"
        :header-cell-style=" {fontWeight:'bold'}"
      >
        <el-table-column
          prop="id"
          label="ID"
          min-width="50"
        />
        <el-table-column label="活动名称"
                         prop="title"
                         min-width="100"
                         :show-overflow-tooltip="true">
		
        </el-table-column>
		<el-table-column label="所属人"
		                 prop="owner_name"
		                 min-width="100"
		                 :show-overflow-tooltip="true">
		</el-table-column>
		
        <el-table-column
          label="添加时间"
          min-width="120"
          align="center"
        >
          <template slot-scope="scope">
            <span>{{ scope.row.add_time }}</span>
          </template>
        </el-table-column>
		<el-table-column
		  label="更新时间"
		  min-width="120"
		  align="center"
		>
		  <template slot-scope="scope">
		    <span>{{ scope.row.update_time }}</span>
		  </template>
		</el-table-column>
		
        <el-table-column label="操作" min-width="130" fixed="right">
          <template slot-scope="scope">
			<el-button type="text" @click="editRow(scope.row,1)">编辑活动规则</el-button>
			<el-button type="text" @click="editRow(scope.row,2)">编辑活动教程</el-button>
			<el-button type="text" @click="delRow(scope.row.id)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
	  <div class="page">
	              <el-pagination
	                      background
	                      @size-change="pageChange"
	                      @current-change="handleCurrentChange"
	                      :current-page="page"
	                      :page-size="pageSize"
	                      layout="total, sizes, prev, pager, next, jumper"
	                      :total="page_totle">
	              </el-pagination>
	          </div>
    </el-card>
	
	<!-- 新增角色 -->
	<el-dialog
	  title="活动规则"
	  :visible.sync="formShow"
	  :close-on-click-modal="false"
	  width="1000px">
	  <el-form ref="form" :model="form" label-width="120px">
		  <edit v-if="formShow" ref="myEdit" />
	  </el-form>
	  <span slot="footer" class="dialog-footer">
	    <el-button size="mini" @click="formShow = false">取 消</el-button>
	    <el-button size="mini" type="primary" @click="confirm">确 定</el-button>
	  </span>
	</el-dialog>
  </div>
</template>
<script>
	import  edit  from "@/components/wangEditor.vue"
  export default {
	components:{
		edit
	},
    data() {
      return {
        title:'新增',
		isShow:false,
		form:{
			id:null,
			content:"",
			active_course:''
		},
		list:[],
		page:1,
		pageSize:10,
		table_name:"customer_group",
		shopUser:[],
		userList:[],
		groupList:[],
		group_chat_list:[],
		group_chat:{
			name:""
		},
		type:"",
		searchForm:{
			title:"",
			owner_id:""
		},
      }
    },
    mounted() {
      this.lodeList()
	  this.lodeStaffList()
    },
    methods: {
		reset(){
			this.searchForm = {
				title:"",
				owner_id:""
			}
			this.mySearch()
		},
		lodeStaffList(){
				 
			this.$api.post('/sadmin/getEmpList',{}).then(res=>{
						  let data = res.data
						  this.shopUser = data.result
			})
		},
		editRow(row,type){
			
			this.type = type
			this.addTitle = '编辑'
			for(let i in this.form){
				this.form[i] = row[i]
			}
			setTimeout(()=>{
				
			    // window.$editor.txt.html(row.content)
				if(type==1){
					this.$refs.myEdit.html = row.content
				}else{
					this.$refs.myEdit.html = row.active_course
				}
			    
				
			},100)
			this.formShow = true
		
		},
		
		confirm(){
			let params = {
				id:this.form.id,
				// content:this.$refs.myEdit.html
			}
			if(this.type==1){
				params.content = this.$refs.myEdit.html
			}else{
				params.active_course = this.$refs.myEdit.html
			}
		    this.$api.post('/sadmin/editActiveRule',params).then(res=>{
		    	  if(res.code==200){
					  this.formShow = false
		    	  	this.lodeList()
		    	  }
		    })
		},
		delRow(id){
			this.$confirm('确定删除', '提示', {
					  confirmButtonText: '确定',
					  cancelButtonText: '取消',
					  type: 'warning'
					}).then(() => {
						let params = {
							dd:{id}
						}
					  this.$api.post('/sadmin/delActive',params).then(res=>{
					  	  if(res.code==200){
					  	  	this.lodeList()
					  	  }
					  })
			  })
	   },
      lodeList(){
		  let map = []
		  if(this.searchForm.title){
			map.push(
			  [
				'title','like','%'+this.searchForm.title+'%'
			  ]
			)
		  }
		  if(this.searchForm.owner_id){
			map.push(
			  [
				'owner_id','=',this.searchForm.owner_id
			  ]
			)
		  }
		  let params = {
		          	page:this.page,
		          	pageSize:this.pageSize,
					map:map
		    }
		 
		  this.$api.post('/sadmin/getActivityList',params).then(res=>{
			  let data = res.data
			  this.page_totle = data.count
			  this.list = data.result
		  })
	  }
      
    }
  }
</script>
